package cn.edu.zafu.bigdata.lwg;

 class Cube {
    private double length;
    private double width;
    private double height;

    public Cube(double length, double width, double height) {
        this.length = length;
        this.width = width;
        this.height = height;
    }

    public double getLength() {
        return length;
    }

    public double getWidth() {
        return width;
    }

    public double getHeight() {
        return height;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null || getClass() != obj.getClass()) {
            return false;
        }
        Cube cube = (Cube) obj;
        return Double.compare(cube.length, length) == 0 &&
                Double.compare(cube.width, width) == 0 &&
                Double.compare(cube.height, height) == 0;
    }

    @Override
    public int hashCode() {
        int result;
        long temp;
        temp = Double.doubleToLongBits(length);
        result = (int) (temp ^ (temp >>> 32));
        temp = Double.doubleToLongBits(width);
        result = 31 * result + (int) (temp ^ (temp >>> 32));
        temp = Double.doubleToLongBits(height);
        result = 31 * result + (int) (temp ^ (temp >>> 32));
        return result;
    }
}


public class TestCube {
    public static void main(String[] args) {
        Cube cube1 = new Cube(1.0, 2.0, 3.0);
        Cube cube2 = new Cube(1.0, 2.0, 3.0);
        Cube cube3 = new Cube(4.0, 5.0, 6.0);

        System.out.println("cube1 equals cube2: " + cube1.equals(cube2));
        System.out.println("cube1 equals cube3: " + cube1.equals(cube3));

        System.out.println("cube1 equals null: " + cube1.equals(null));

        System.out.println("cube1 equals \"String\": " + cube1.equals("String"));
    }
}